import {submitTest, getJudgeResult} from "@/api/hoj-problems.js";
import {ref} from "vue";

// 实现一个基于setTimeout的异步函数
async function wait(timeout) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('Hello, World!');
    }, timeout);
  });
}

export function useProblemJudgement() {
    const isSubmitting = ref(false)
    const error = ref(null)
    const submitProblemTest = async (data) => {
        isSubmitting.value = true
        try {
            const submitResp = await submitTest(data)
            await wait(1000)
            const getResp = await getJudgeResult(submitResp.data)
            return getResp.data
        } catch (e) {
            error.value = e
        }
        isSubmitting.value = true
    }

    return {
        submitProblemTest,
        isSubmitting,
        error
    }
}